﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TeamsPortal.DataAccess;
using TeamsPortal.Validation;

namespace TeamsPortal.ServiceClient
{
    public interface IUsersServiceClient
    {
        User GetByProviderId(AuthenticationProvider provider, string providerId);

        User GetByPasswordResetGuid(AuthenticationProvider provider, string passwordResetGuid);

        User GetTestUser();

        /// <exception cref="ValidationException"></exception>
        User Add(User user, AuthenticationProvider provider, string providerId);

        List<User> GetAll();

        List<User> FindByName(string userName);

        User GetByName(string userName);

        void Delete(int id);

        /// <summary>
        /// Assigns the next (up) user group to the user
        /// </summary>
        void Promote(int id);

        /// <summary>
        /// Assigns the previous (down) user group to the user
        /// </summary>
        void Demote(int id);

        User Get(int userId);

        string GetRoleName(UserRole userRole);

        /// <exception cref="ValidationException"></exception>
        void Edit(User user);

        /// <summary>
        /// Add the email address to the user profile.
        /// </summary>
        /// <exception cref="ValidationException"></exception>
        void AddEmail(int id, string email, EmailPolicy policy);

        /// <summary>
        /// Updates the user's password reset temporary Guid used for password reset purposes
        /// </summary>
        /// <param name="id">UserId</param>
        /// <param name="Guid">PasswordResetGuid</param>
        /// <param name="expireDate">PasswordResetGuidExpireDate</param>
        void UpdatePasswordResetGuid(int id, string Guid, DateTime expireDate);

        /// <summary>
        /// Tries to authenticate against the custom provider. If success, it gets or creates an application user
        /// </summary>
        /// <returns></returns>
        /// <exception cref="ValidationException">Throws a ValidationException when userName and/or password are empty</exception>
        User AuthenticateWithCustomProvider(string userName, string password);

        /// <summary>
        /// Validates username and password
        /// </summary>
        /// <exception cref="ValidationException">Throws a ValidationException when userName and/or password are empty</exception>
        void ValidateUserAndPassword(string userName, string password);

        /// <summary>
        /// Gets a dictionary containing the user roles and its names.
        /// </summary>
        /// <returns></returns>
        Dictionary<UserRole, string> GetRoles();

        /// <summary>
        /// Determines if a user exist of the application
        /// </summary>
        /// <returns></returns>
        bool IsThereAnyUser();

        /// <summary>
        /// Sets an avatar for user
        /// </summary>
        /// <param name="userId">Id of user who will get the new avatar</param>
        /// <param name="avatar"></param>
        void SetAvatar(int userId, ImageInfo avatar);
    }
}
